import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import BizException from '@libs/common/dto/biz.exception';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const PORT = AppModule.loadYaml().application.port
  app.useGlobalPipes(new ValidationPipe({
    transform: true,
    enableDebugMessages: false,
    stopAtFirstError: true,
    exceptionFactory(errors) {
      const [error] = errors
      const [errorText] = Object.values(error.constraints)
      return new BizException(errorText, 500)
    }
  }));
  await app.listen(PORT);
  console.log(`启动成功 http://localhost:${PORT}`)
}
bootstrap();
